#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import os.path
import re

#from __future__ import with_statement

dir_source = '/home/maxk69/public_html/upload'

dir_cible = '/home/maxk69/public_html/admin/import'

for i in os.listdir(dir_source):
	if re.search("txt$", os.path.splitext(i)[1], re.I):
		source = open(os.path.join(dir_source, i))
		cible = open(os.path.join(dir_cible, os.path.splitext(i)[0] + '.csv'), 'w')
		cible.write('"Email Address"\n')
		for line in source.readlines():
			line = re.sub("\\r$", "", re.sub("\\n$", "", line))
			cible.write('"' + line + '"\n')
		cible.close()
